<?php
class Wxpay extends Base_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model("wxpay_model");
    }

    public function prepay()
    {
        $uid = $this->input->input_stream('uid');
        $openid = $this->input->input_stream('openid');
        $num = $this->input->input_stream('num');

        if(isset($uid)&&is_numeric($uid)) $uid = (int)$uid;
        else $this->error('user not login');
        if(!isset($openid)||empty($openid)) $this->error('user not login');
        if(isset($num)&&is_numeric($num)) $num = (int)$num;
        else $this->error('lack charge num');
        $res = $this->wxpay_model->addOrder($openid,$uid,$num);
        if ($res === false ) $this->error('invalid request');
        else $this->success($res);
    }

//    public function nativepay()
//    {
//        $uid = $this->input->input_stream('uid');
//        $num = $this->input->input_stream('num');
//
//        if(isset($uid)&&is_numeric($uid)) $uid = (int)$uid;
//        else $this->error('user not login');
//        if(isset($num)&&is_numeric($num)) $num = (int)$num;
//        else $this->error('lack charge num');
//        $res = $this->wxpay_model->nativeOrder($uid,$num);
//        if (empty($res['url'])) $this->error('invalid request');
//        else $this->success($res);
//    }
//
//    public function qrcode()
//    {
//        $url = $this->input->get('data');
//        if (isset($url)) $url=urldecode($url);
//        else $this->error('lack url');
//        $this->wxpay_model->qrcode($url);
//    }
    public function callback()
    {
        $this->wxpay_model->callback();
    }
}